import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Input, Picker, Image, Textarea, Form, Button } from "@tarojs/components-rn";
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, enterpriseQualificationArr, taxTypesArr, projectPriceArr } from "../../utils/common";
import PageFooterInfo from "../../components/PageFooterInfo";
import page4_demandStyleSheet from "./page4_demand_styles";

import right from '../../assets/img/right.png';
import PickerArea from "../../components/PickerArea";
var _styleSheet = page4_demandStyleSheet;
let Page3 = class Page3 extends Component {
  constructor(props) {
    super(props);
    this.state = {
      projectName: '',
      projectTypeArr: ['政府投资公建项目', '政府投资非公建项目', '社会民资商业建设项目', '社会民资非盈利建设项目'],
      projectType: '',
      area: null,
      areaCode: null,
      allAreaCode: '',
      projectPriceArr: projectPriceArr,
      projectPrice: null,
      companyName: '',
      natureOfTheFirmArr: ['全民所有制企业(即国有企业)', '集体所有制企业', '联营企业', '三资企业', '私营企业及其他企业'],
      natureOfTheFirm: '',
      enterpriseScaleArr: ['1-49人', '50-100人', '大于100人'],
      enterpriseScale: '',
      enterpriseQualificationArr: enterpriseQualificationArr,
      enterpriseQualification: '',
      taxTypesArr: taxTypesArr,
      taxTypes: '',
      enterpriseAddress: '',
      remarks: '',
      contactsName: '',
      phoneNumnber: '',
      wechatNumber: '',
      qqNumber: '',
      allProvince: [],
      allCity: [],
      provinceIndex: 0,
      cityIndex: 0
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '发布项目信息' });
    this.getAllProvince();
    this.getAllCity(-1);
  }
  getAllProvince() {
    let { AreaStore } = this.props.stores;
    AreaStore.getAllProvinceFromLocal({
      callBack: res => {
        //console.log(res)
        this.setState({
          allProvince: res
        });
      }
    });
  }
  getAllCity(index = 0) {
    let { AreaStore } = this.props.stores;
    AreaStore.getAllCityFromLocal({
      index,
      callBack: res => {
        //console.log(res)
        this.setState({
          allCity: res
        });
      }
    });
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  changePicker(field, e) {
    // let arr = fie
    this.setState({
      [field]: this.state[field + 'Arr'][e.detail.value]
    });
  }
  pickerArea(res) {
    this.setState({
      area: res.province.label + res.city.label + res.distract.label,
      areaCode: res.distract.value,
      allAreaCode: res.province.value + ',' + res.city.value + ',' + res.distract.value
    });
  }
  saveProjectInfo(e) {
    let { projectType, projectPrice, natureOfTheFirm, enterpriseScale, enterpriseQualification, taxTypes, area, areaCode, allAreaCode } = this.state;
    let { projectName, companyName, enterpriseAddress, remarks, contactsName, phoneNumnber, wechatNumber, qqNumber } = e.detail.value;
    // 数据验证
    if (!projectName) {
      getRuntime().showToast('项目名称不能为空~');
      return;
    }
    if (!projectType) {
      getRuntime().showToast('项目类型不能为空~');
      return;
    }
    if (!companyName) {
      getRuntime().showToast('公司名称不能为空~');
      return;
    }
    if (!contactsName) {
      getRuntime().showToast('联系人姓名不能为空~');
      return;
    }
    if (!phoneNumnber) {
      getRuntime().showToast('联系人电话不能为空~');
      return;
    }
    let { FinancialCenterStore } = this.props.stores;
    FinancialCenterStore.saveProjectInfo({
      form: {
        projectName, projectType, projectPrice, companyName, natureOfTheFirm, enterpriseScale, enterpriseQualification, taxTypes, area, areaCode, allAreaCode,
        enterpriseAddress, remarks, contactsName, phoneNumnber, wechatNumber, qqNumber
      },
      callback: () => {
        // /pages/finance/finance_success
        getRuntime().navigateTo('/pages/finance/finance_success');
      }
    });
  }
  render() {
    let { projectTypeArr, projectPriceArr, natureOfTheFirmArr, enterpriseScaleArr, enterpriseQualificationArr, taxTypesArr, projectType, projectPrice, natureOfTheFirm, enterpriseScale, enterpriseQualification, taxTypes, area, allProvince, allCity } = this.state;
    return <View style={_styleSheet["from-wrap"]}>

       <Form onSubmit={this.saveProjectInfo.bind(this)}>
         <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>项目名称</View>
             <Input placeholderClass="placeholder_class" placeholder="请填写项目名称" name="projectName" style={_styleSheet["from-input"]} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>项目类型</View>
             <Picker mode="selector" name={'projectType'} range={projectTypeArr} onChange={this.changePicker.bind(this, 'projectType')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{projectType}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>

           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>所在地区</View>
             <PickerArea onPicketArea={this.pickerArea.bind(this)} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>项目价格</View>
             <Picker mode="selector" name={'projectPrice'} range={projectPriceArr} onChange={this.changePicker.bind(this, 'projectPrice')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{projectPrice}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>
         </View>

         <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>企业名称</View>
             <Input name={'companyName'} placeholderClass="placeholder_class" placeholder="请填写企业名称" style={_styleSheet["from-input"]} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>企业性质</View>
             <Picker name={'natureOfTheFirm'} mode="selector" range={natureOfTheFirmArr} onChange={this.changePicker.bind(this, 'natureOfTheFirm')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{natureOfTheFirm}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>企业规模</View>
             <Picker name={'enterpriseScale'} mode="selector" range={enterpriseScaleArr} onChange={this.changePicker.bind(this, 'enterpriseScale')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{enterpriseScale}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>企业资质</View>
             <Picker name={'enterpriseQualification'} mode="selector" range={enterpriseQualificationArr} onChange={this.changePicker.bind(this, 'enterpriseQualification')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{enterpriseQualification}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>纳税类型</View>
             <Picker name={'taxTypes'} mode="selector" range={taxTypesArr} onChange={this.changePicker.bind(this, 'taxTypes')} style={_styleSheet["input-picker"]}>
               <View style={_styleSheet["tt"]}>
                 <View style={[_styleSheet["from-input"], _styleSheet["picker-con"]]}>{taxTypes}</View>
                 <Image src={right} style={_styleSheet["drop-down-icon"]} />
               </View>
             </Picker>
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>企业地址</View>
             <Input name={'enterpriseAddress'} placeholderClass="placeholder_class" placeholder="请填写企业地址" style={_styleSheet["from-input"]} />
           </View>
         </View>

         <View style={_styleSheet["input-group"]}>
           <Textarea name={'remarks'} placeholderClass="placeholder-class" placeholder="请填写相关的备注内容" maxlength={-1} style={_styleSheet["from-textarea"]} />
         </View>
         <View style={_styleSheet["interval"]} />

         <View style={[_styleSheet["item-group"], _styleSheet["pt0"], _styleSheet["pb0"]]}>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系人</View>
             <Input name={'contactsName'} placeholderClass="placeholder_class" placeholder="请填写联系人" style={_styleSheet["from-input"]} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={[_styleSheet["input-name"], _styleSheet["is-require"]]}>联系电话</View>
             <Input type="number" maxLength={11} name={'phoneNumnber'} placeholderClass="placeholder_class" placeholder="请填写联系电话" style={_styleSheet["from-input"]} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>微信号</View>
             <Input name={'wechatNumber'} placeholderClass="placeholder_class" placeholder="请填写微信号" style={_styleSheet["from-input"]} />
           </View>
           <View style={_styleSheet["input-group"]}>
             <View style={_styleSheet["input-name"]}>QQ号</View>
             <Input type={"number"} maxLength={11} name={'qqNumber'} placeholderClass="placeholder_class" placeholder="请填写QQ号" style={_styleSheet["from-input"]} />
           </View>
         </View>

         <Button formType="submit" style={_styleSheet["page-submit"]}>立即发布</Button>
       </Form>

        <PageFooterInfo />

      </View>;
  }
};
Page3 = tslib_1.__decorate([inject("stores"), observer], Page3);
export default Page3;